/***************************************************************************
 *   Copyright (C) 2006 by Sergey Melderis   *
 *   sergey.melderis@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef WORDSTOFILEWRITER_H
#define WORDSTOFILEWRITER_H

#include <qobject.h>
#include <qmap.h>
class QString;
class QFile;
class QDomDocument;
class QDomElement;
/**
	@author Sergey Melderis <sergey.melderis@gmail.com>

	Class writes to existing wordquiz files.
*/
class WordQuizWriter : public QObject
{
Q_OBJECT
public:
    WordQuizWriter(QObject *parent = 0, const char *name = 0);


    ~WordQuizWriter();

    void reconfigure();
signals:
    void addWordCompleted(const QString &resultString);
public slots:
    void addWord(const QString &fileName, const QString &word, const QString &translation);

private:
    QMap<QString, QString> mFilesMap;

    bool isWordExist(const QDomDocument &doc, const QString &word,
                     const QString &transl, QDomElement &parentCandidate);

    void addWordToDocument(QDomDocument &doc, const QString &orig, const QString &tran);

    void addDataToElement(QDomDocument &doc, QDomElement &element,
                          const QString &orig, const QString &tran);

    void showErrorDialog(const QString &error);
};

#endif
